package Com.Hupochuan.Dal.DBLink;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBLink {
	private static final String DBDRIVER = "com.mysql.jdbc.Driver";

	private final String DBURL = "jdbc:mysql://127.0.0.1:3308/hupochuan?useUnicode=true&amp;characterEncoding=utf-8";
	private final String DBUSER = "root";
	private final String DBPASSWORD ="1992jyl521621e";

	static {
		try {
			Class.forName(DBDRIVER);
		} catch (Exception e) {
		}
	}
	
	/*
	 * 单一实例
	 */
	private DBLink(){}
	private static DBLink dbLink = new DBLink();
	public static DBLink getObject(){
		return dbLink;
	}

	/*
	 * 获得链接
	 */
	public Connection getConn() {
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	/*
	 * 关闭 结果集 命令 链接
	 */
	public void close(ResultSet rs, PreparedStatement ps, Connection conn) {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			rs = null;
		}
		if (ps != null) {
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			ps = null;
		}
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			conn = null;
		}
	}
}
